home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / a2 / Source / vidout.c < prev    next >
Encoding:
Text File  |  1992-03-21  |  2.0 KB  |  120 lines

  1. /*
  2.  *  a2, an Apple II emulator in C
  3.  *  (c) Copyright 1990 by Rich Skrenta
  4.  *
  5.  *  Command line interface written by Tom Markson
  6.  *
  7.  *  Distribution agreement:
  8.  *
  9.  *    You may freely copy or redistribute this software, so long
  10.  *    as there is no profit made from its use, sale, trade or
  11.  *    reproduction.  You may not change this copyright notice,
  12.  *    and it must be included prominently in any copy made.
  13.  *
  14.  *  Send emulator related mail to:  skrenta@blekko.commodore.com
  15.  *                    skrenta@blekko.uucp
  16.  */
  17.  
  18.  
  19.  
  20. #import    <stdio.h>
  21. #import "a2.h"
  22.  
  23.  
  24. #define        WNDLFT        0x20
  25. #define        WNDWDTH        0x21
  26. #define        WNDTOP        0x22
  27. #define        WNDBTM        0x23
  28. #define        CH        0x24
  29. #define        CV        0x25
  30. #define        BASL        0x28
  31. #define        BASH        0x29
  32. #define        BAS2L        0x2A
  33. #define        BAS2H        0x2B
  34.  
  35.  
  36.  
  37. /*
  38.  *  SCROLL at $FC70
  39.  */
  40.  
  41. void scroll(void)
  42. {
  43. int top;
  44. unsigned short bas, bas2, ptr;
  45. int width;
  46. int i;
  47. int scrl2_normal;
  48.  
  49.     if (mem[0x21] == 40 && mem[0x22] == 0 && mem[0x23] == 24) {
  50.         MoveCursor(term_lines, 0);
  51.         putchar('\n');
  52.         last_line = -1;
  53.         last_col = -1;
  54.         fflush(stdout);
  55.         scrl2_normal = FALSE;
  56.     } else
  57.         scrl2_normal = TRUE;
  58.  
  59.     top = mem[WNDTOP];
  60.     width = mem[WNDWDTH] - 1;
  61.     bas = text1[top % 32] + mem[WNDLFT];
  62.  
  63.     while (1) {
  64.         bas2 = bas;
  65.  
  66.         if (++top >= mem[WNDBTM]) {
  67.             mem[BASL] = low(bas);
  68.             mem[BASH] = high(bas);
  69.             Pc = 0xFC95;
  70.             fflush(stdout);
  71.             return;
  72.         }
  73.  
  74.         bas = text1[top % 32] + mem[WNDLFT];
  75.         ptr = bas;
  76.  
  77.         if (scrl2_normal)
  78.             for (i = 0; i <= width; i++)
  79.                 set_text1f(bas2++, mem[ptr++]);
  80.         else
  81.             for (i = 0; i <= width; i++)
  82.                 mem[bas2++] = mem[ptr++];
  83.     }
  84. }
  85.  
  86. /*
  87.  *  VIDOUT at $FBFD
  88.  */
  89.  
  90. void vidout(void)
  91. {
  92. unsigned short ptr;
  93.  
  94.     if (A >= 0xA0 || A < 0x80) {
  95.         ptr = join(mem[BASL], mem[BASH]) + mem[CH];
  96.         set_text1f(ptr, A);
  97.         mem[CH]++;
  98.         if (mem[CH] >= mem[WNDWDTH])
  99.             mem[CH] = 0;
  100.         else {
  101.             DO_RTS;
  102.             return;
  103.         }
  104.     } else if (A == 0x8D)
  105.         mem[CH] = 0;
  106.     else if (A != 0x8A) {
  107.         Pc = 0xFC0C;
  108.         return;
  109.     }
  110.  
  111.     A = ++mem[CV];
  112.     if (A < mem[WNDBTM]) {
  113.         Pc = 0xFC24;
  114.         return;
  115.     }
  116.     mem[CV]--;
  117.  
  118.     scroll();
  119. }
  120.